package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import vo.ListPricing;

public class ListPricingDao {

	private Statement pmt=null;
	
	public ListPricingDao(){}
	
public ListPricing getListPricing(Connection con) throws Exception{
		try{
		ListPricing resultlistPricing=null;
		String sql="select * from source";
		Statement ptmt=con.createStatement();
		ResultSet rs=ptmt.executeQuery(sql);
		while(rs.next()){
			resultlistPricing=new ListPricing();
			resultlistPricing.setName(rs.getString(1));
			resultlistPricing.setMonth_rent(rs.getString(2));
			resultlistPricing.setHour_spent(rs.getString(3));
			resultlistPricing.setIntroduce(rs.getString(4));
			
		}
		return resultlistPricing;
		}finally{
			if(null!=pmt){
				pmt.close();
			}
			
			if(null!=con){
				con.close();
			}
		}
	} 

	public void addPricing(Connection con,String pricingName,String baseFee,String rateFee,String pricingDesc) throws Exception{
		
		try{
			
			String sql="insert into source "+"(name,month_rent,hour_spent,introduce)"+"values("+"'"+pricingName+"'"+
				","+"'"+baseFee+"'"+","+"'"+rateFee+"'"+","+"'"+pricingDesc+"'"+")";
			pmt=con.createStatement();
			pmt.executeUpdate(sql);
			pmt.close();
			con.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}

}
